import { PlaceEditing } from "@czmSrc/EditingSystem/base";
import { ESCesiumViewer } from "@czmSrc/ESCesiumViewer";
import { equalsN3, ESJEditingMode, ESSceneObject } from "earthsdk3";
import { bind, nextAnimateFrame } from "xbsj-base";
import { BaseEditingWrapper } from "./BaseEditingWrapper";
export class PlaceEditingWrapper extends BaseEditingWrapper {
    static readonly type = this.registerEditing("ESCesiumViewer", ESJEditingMode.Place, this);
    constructor(sceneObject: ESSceneObject, czmViewer: ESCesiumViewer) {
        super(sceneObject, czmViewer, true);
        const placeEditing = this.currentEditing = this.ad(new PlaceEditing(czmViewer))
        this.ad(czmViewer.clickEvent.don((e) => {
            e.pointerEvent?.button == 2 && (placeEditing.enabled = true);
        }))
        this.ad(czmViewer.dblclickEvent.don(() => {
            this.ad(nextAnimateFrame(() => {
                this.destroy();
            }));
        }))
        do {
            if (Reflect.has(sceneObject, 'position')) {
                //@ts-ignore
                this.ad(bind([placeEditing, 'position'], [sceneObject, 'position']));
                placeEditing.enabled = !placeEditing.position || equalsN3(placeEditing.position, [0, 0, 0]);
                break;
            }
            this.supportEditing = false;
        } while (false);
    }
}